<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>阿拉伯数字转中文数字</title>
</head>

<body>
    <script>
        function arabicToChinese(num) {
            var chnNumChar = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
            var chnUnitChar = ["", "十", "百", "千", "万", "亿", "万亿", "亿亿"];
            var strIns = "",
                chnStr = "";
            var unitPos = 0;
            var zero = true;
            while (num > 0) {
                // 从个位开始处理数字，每次处理一位
                var v = num % 10;
                if (v === 0) {
                    if (!zero) {
                        zero = true;
                        chnStr = chnNumChar[v] + chnStr;
                    }
                } else {
                    zero = false;
                    strIns = chnNumChar[v];
                    strIns += chnUnitChar[unitPos];
                    chnStr = strIns + chnStr;
                }
                unitPos++;
                num = Math.floor(num / 10);
            }
            return chnStr;
        }

        console.log(arabicToChinese(1));
        console.log(arabicToChinese(2));
        console.log(arabicToChinese(3));
        console.log(arabicToChinese(4));
        console.log(arabicToChinese(5));
        console.log(arabicToChinese(6));
        console.log(arabicToChinese(7));
        console.log(arabicToChinese(8));
        console.log(arabicToChinese(9));
        console.log(arabicToChinese(10));
        console.log(arabicToChinese(11));
        console.log(arabicToChinese(20));
        console.log(arabicToChinese(10000));

        // const numberToChinese = (num) => {
        //     if (!num) {
        //         return
        //     }
        //     const chineseNum = '零,一,二,三,四,五,六,七,八,九'.split(',')
        //     const chineseUnit = ',十,百,千,万'.split(',')
        //     const numStr = num.toString()
        //     let chineseStr = ''
        //     for (let i = 0; i < numStr.length; i++) {
        //         let index = +numStr[i]
        //         chineseStr += chineseNum[index]
        //     }

        //     return chineseStr
        // }
    </script>
</body>

</html>